// pages/dindanzifu/index.js
import {
  dingdanSubmit
} from '../../apis/index';
import {
  getDetaulAddresId,
  getAddressList
} from '../../apis/index'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    detail: [],
    defaultSelected: '',
    addressList: [],
    defaultId: ''
  },
  changeAdress() {
    wx.navigateTo({
      url: '/pages/user/adress/index',
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log('参数', options)
    wx.request({
      url: 'http://192.168.76.39/index.php?s=/api/goods/detail',
      data: {
        goodsId: options.goodsId,
      },
      success: res => {
        console.log(res.data.data.detail)
        this.setData({
          detail: res.data.data.detail,
        })
      }
    })
  },

  dingdanSubmit(e) {
    const goodsId = this.options.goodsId
    const goodsSkuId = "0"
    const res = dingdanSubmit({
      data: {
        couponId: 0,
        delivery: 10,
        goodsId: goodsId,
        goodsNum: 1,
        goodsSkuId: goodsSkuId,
        isUsePoints: 0,
        mode: "buyNow",
        payType: 10,
        remark: "留言",
      }
    })
    console.log(res)
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
    this.initData()
  },
  async initData() {
    const res = await getAddressList()
    console.log("收货地址列表", res)
    if (res.status === 200) {
      this.setData({
        addressList: res.data.list || []
      })
    }
    let address = res.data.list[0]
    let region = address.region
    console.log(region)
    let addrDetail = region.province + "/" + region.city + "/" + region.region + '/' + address.detail
    
    this.setData({
      addressList: addrDetail
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})